/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include "../结构数据.h"



typedef struct {
	vec2* ptr_userData;
	uint32	count;
}S_凸边顶点;

typedef struct {
	float 角度;
	uint32	ID;
}S_凸边顶点排序元素;

typedef struct {
	S_凸边顶点排序元素*	ptr_userData;
	uint32				count;
}S_凸包顶点排序;

uint32 f_graph_计算最大X索引(const vec2* point, uint32 num);
uint32 f_graph_计算最大Y索引(const vec2* point, uint32 num);

uint32 f_graph_计算2D凸包(vec2* point, uint32 num, S_凸边顶点* rv);


Inline S_凸边顶点* f_凸边_创建() {
	return (S_凸边顶点*)f_core_array_new(0, sizeof(vec2));
}

Inline void f_凸边_销毁(S_凸边顶点* cv) {
	f_core_array_free((S_Array*)cv);
}

Inline void f_凸边_添加顶点(S_凸边顶点* cv, const vec2& point) {
	f_core_array_push_back((S_Array*)cv, (const uint8*)&point);
}
Inline void f_凸边_设置末尾顶点(S_凸边顶点* cv, const vec2& point) {
	*((vec2*)f_core_array_at((S_Array*)cv, cv->count-1)) = point;
}
Inline void f_凸边_删除末尾顶点(S_凸边顶点* cv) {
	f_core_array_pop_back((S_Array*)cv);
}
Inline void f_凸边_清除顶点(S_凸边顶点* cv) {
	cv->count = 0;
}


//Inline S_凸边顶点排序元素* 

Inline S_凸包顶点排序* f_凸边顶点排序_创建(uint32 num) {
	return (S_凸包顶点排序*)f_core_array_new(num, sizeof(S_凸边顶点排序元素));
}
Inline void f_凸边顶点排序_销毁(S_凸包顶点排序* cv) {
	f_core_array_free((S_Array*)cv);
}
Inline void f_凸边顶点排序_设置元素(S_凸包顶点排序* cv, uint32 offset, const S_凸边顶点排序元素& point) {
	(*(S_凸边顶点排序元素*)f_core_array_at((S_Array*)cv, offset)) = point;
}



void f_凸边顶点排序_排序(S_凸包顶点排序* cv);




